package co.edu.javeriana.monopoly.client.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import co.edu.javeriana.monopoly.model.IPropiedad;
import co.edu.javeriana.monopoly.model.Propiedad;

/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class PropiedadPanel extends JPanel {

    public final static int INVERSEHORIZONTAL = 4;
    public final static int INVERSEVERTICAL = 2;
    public final static int HORIZONTAL = 3;
    public final static int VERTICAL = 1;
    /**
     *
     */
    private static final long serialVersionUID = -2789132931441891056L;
    private int direction;
    private int height = 55;
    private JLabel imagen;
    private IPropiedad propiedad;
    private JLabel text;
    private int width = 110;
    private JPanel zone;

    /**
     * Constructor
     *
     */
    public PropiedadPanel() {
        super();
        setWidth(110);
        setHeight(55);
        IPropiedad prop = new Propiedad();
        prop.setNombre("Lugar");
        prop.setZone(IPropiedad.ZONE3);
        setPropiedad(prop);
        setDirection(PropiedadPanel.HORIZONTAL);
        init();
    }

    /**
     * Constructor
     *
     */
    public PropiedadPanel(IPropiedad propiedad, int width, int height, int direction, ImageIcon image) {
        super();
        setWidth(width);
        setHeight(height);
        setPropiedad(propiedad);
        setDirection(direction);
        setImagen(image);
        init();
    }

    public int getDirection() {
        return direction;
    }

    public int getHeight() {
        return height;
    }

    public IPropiedad getPropiedad() {
        return propiedad;
    }

    public int getWidth() {
        return width;
    }

    public void init() {
        this.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        this.setLayout(new BorderLayout(0, 0));
        //this.setSize ( new Dimension ( width, height ) );
        this.setPreferredSize(new Dimension(width, height));
        //this.setMaximumSize ( new Dimension ( width, height ) );
        //this.setMinimumSize ( new Dimension ( width, height ) );

        zone = new JPanel();
        zone.setBackground(propiedad.getZone());
        zone.setPreferredSize(new Dimension(width, height / 5));

        text = new JLabel();
        Font curFont = text.getFont();
        text.setFont(new Font(curFont.getFontName(), curFont.getStyle(), 8));
        text.setText(propiedad.getNombre());
        text.setPreferredSize(new Dimension(width, height / 5));
        text.setHorizontalAlignment(SwingConstants.CENTER);
        text.setVerticalAlignment(SwingConstants.CENTER);

        /*imagen = new JLabel();
        imagen.setIcon(new ImageIcon(getClass().getResource("/co/edu/javeriana/monopoly/client/images/Transmilenio.gif")));
        imagen.setSize(width, height / 5 * 3);*/
        imagen.setPreferredSize(new Dimension(width, height / 5 * 3));
        //imagen.setAlignmentY(0.0f);
        //imagen.setIconTextGap(0);

        switch (direction) {
            case PropiedadPanel.HORIZONTAL:
                //if ( direction ==  PropiedadPanel.HORIZONTAL ){
                this.setPreferredSize(new Dimension(height, width));
                zone.setPreferredSize(new Dimension(height / 5, width));
                text.setPreferredSize(new Dimension(height / 5, width));
                text.setUI(new RotateLabelUI(270));
                imagen.setPreferredSize(new Dimension(height / 5 * 3, width));
                imagen.setUI(new RotateLabelUI(270));
                this.add(zone, BorderLayout.WEST);
                this.add(imagen, BorderLayout.CENTER);
                this.add(text, BorderLayout.LINE_END);
                break;
            //}
            //if ( direction ==  PropiedadPanel.INVERSEHORIZONTAL ){
            case PropiedadPanel.INVERSEHORIZONTAL:
                this.setPreferredSize(new Dimension(height, width));
                zone.setPreferredSize(new Dimension(height / 5, width));
                text.setPreferredSize(new Dimension(height / 5, width));
                text.setUI(new RotateLabelUI(90));
                imagen.setPreferredSize(new Dimension(height / 5 * 3, width));
                imagen.setUI(new RotateLabelUI(90));
                this.add(text, BorderLayout.WEST);
                this.add(imagen, BorderLayout.CENTER);
                this.add(zone, BorderLayout.LINE_END);
                break;
            //}
            //if ( direction ==  PropiedadPanel.VERTICAL ){
            case PropiedadPanel.VERTICAL:
                text.setBorder(BorderFactory.createBevelBorder(3));
                this.add(zone, BorderLayout.NORTH);
                this.add(imagen, BorderLayout.CENTER);
                this.add(text, BorderLayout.SOUTH);
                break;
            //}
            //if ( direction ==  PropiedadPanel.INVERSEVERTICAL ){
            //{
            case PropiedadPanel.INVERSEVERTICAL:
                text.setUI(new RotateLabelUI(180));
                imagen.setUI(new RotateLabelUI(180));
                this.add(zone, BorderLayout.SOUTH);
                this.add(imagen, BorderLayout.CENTER);
                this.add(text, BorderLayout.NORTH);
                //this.add ( zone );
                text.setSize(width, height / 5);
                break;
        }
        this.setToolTipText(propiedad.getNombre());
        this.setAlignmentX(0.0f);
        this.setAlignmentY(0.0f);
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void setPropiedad(IPropiedad propiedad) {
        this.propiedad = propiedad;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setImagen(ImageIcon imagen) {
        this.imagen = new JLabel();
        this.imagen.setIcon(imagen);
    }
}
